package main.java.game.item;

import main.java.game.Player;
import main.java.game.combatant.Hero;

public class Shield extends AffordableEquipable {
	public Shield(String name, Integer defenseValue, Integer initValue, Integer buyingPrice, ShieldType type){	
		
		super(name, defenseValue,0,initValue,buyingPrice);
		this.setType(type);

	}
	private ShieldType type;

	@Override
	public String toString() {
		return "Shield [cardName=" + getName() + ", atkValue=" + getAttackValue()
				+ ", defValue=" + getDefValue() + ", initValue="
				+ getInitValue() + ", price=" + "]";
	}

	@Override
	public int hashCode() {
		return super.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Shield other = (Shield) obj;
		if (getAttackValue() == null) {
			if (other.getAttackValue() != null)
				return false;
		} else if (!getAttackValue().equals(other.getAttackValue()))
			return false;
		if (getDefValue() == null) {
			if (other.getDefValue() != null)
				return false;
		} else if (!getDefValue().equals(other.getDefValue()))
			return false;
		if (getInitValue() == null) {
			if (other.getInitValue() != null)
				return false;
		} else if (!getInitValue().equals(other.getInitValue()))
			return false;
		return true;
	}

	@Override
	public void equip(Hero h) {
		if(h.getShield()!=null)
			this.unequip(h);
		Player p=h.getPlayer();
		h.setInit(h.getInit()+getInitValue());
		h.setAttack(h.getAttack()+getAttackValue());
		h.setDefense(h.getDefense()+getDefValue());
		h.setShield(this);
		p.removeShield(this);
		
	}

	@Override
	public void unequip(Hero h) {
		Shield s=h.getShield();
		Player p=h.getPlayer();
		p.addShield(s);
		h.setInit(h.getInit()-getInitValue());
		h.setAttack(h.getAttack()-getAttackValue());
		h.setDefense(h.getDefense()-getDefValue());
		h.setShield(null);
	}

	public void setType(ShieldType type) {
		this.type = type;
	}

	public ShieldType getType() {
		return type;
	}

}
